﻿using AdvancedTool.Standard;
using DiskToolSDK;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using static System.Console;
using AdvancedTool;
using System.Runtime.Serialization.Formatters.Binary;
using DiskToolSDK.Basic;

namespace DiskTool
{


    class Program
    {
        static CoreBase[] corepart;
        static void MainMenu()
        {
            WriteLine("1.模块选择  2.设置");
            ConsoleInput input = new ConsoleInput();
            int c = input.ReadInt("请选择功能：", 1, 2);
            switch (c)
            {
                case 1:
                    FunctionSelector(corepart, CoreType.Feature);
                    break;
                case 2:
                    FunctionSelector(corepart, CoreType.Setting);
                    break;
            }
            Console.Clear();
            MainMenu();
        }
        static CoreBase[] ReadCoreBases()
        {
            return new CoreBase[] { new ModSelect(), new ModReader() };
        }
        static List<CoreBase> Selector(CoreBase[] cores, CoreType type)
        {
            int t = 0;
            List<CoreBase> bases = new List<CoreBase>();
            for (int i = 0; i < cores.Length; i++)
            {
                if (cores[i].Type == type)
                {
                    bases.Add(cores[i]);
                }
            }
            return bases;
        }
        static void Show(CoreBase[] cores)
        {
            for (int i = 0; i < cores.Length; i++)
            {
                WriteLine($"{i} {cores[i].Title}\n介绍:{cores[i].Introduce}");
                WriteLine();
            }

        }

        static void FunctionSelector(CoreBase[] cores, CoreType type)
        {
            WriteLine(type == CoreType.Setting ? "设置功能:" : "功能模块:");
            var arr = Selector(cores, type).ToArray();
            ConsoleInput input = new ConsoleInput();
            while (true)
            {
                Show(arr);
                int c = input.ReadInt($"请选择功能(有效输入-1至{arr.Length - 1})：", -1, arr.Length - 1);
                if (c == -1)
                {
                    WriteLine("输入C以确认退出");
                    string comfirm = ReadLine();
                    if (comfirm.ToUpper().Equals("C"))
                        break;
                }
                else
                {
                    arr[c].Function();
                    Console.Clear();
                }
            }
        }


        static void Main(string[] args)
        {
            corepart = ReadCoreBases();
            for (int i = 0; i < corepart.Length; i++)
                corepart[i].Pre_Do();
            MainMenu();
        }
    }
}
